package com.seven.dao;

import java.util.List;

import com.seven.entity.Worker;

//员工dao
public class AWorkerDao extends BaseDao{
	/**
	 * 员工的增加
	 */
	public int addWorker(Worker worker) {
		String sql = "insert into worker(worker_name,worker_username,worker_password,worker_score,worker_state)values(?,?,?,?,?)";
		Object[] ob = {worker.getWorker_name(),worker.getWorker_username(),worker.getWorker_password(),worker.getWorker_score()};
		return super.update(sql, ob);
		
	}
	
	/**
	 * 员工的修改(对密码,工作状态和工分)
	 */
	public int updateWorker(Worker worker) {
		String sql = "update worker set worker_name = ?,worker_username = ?,worker_password = ?,worker_score = ? worker_state = ? where worker_id=?";
		Object[] ob = {worker.getWorker_name(),worker.getWorker_username(),worker.getWorker_password(),worker.getWorker_score(),worker.getWorker_state(),worker.getWorker_id()};
		return super.update(sql, ob);
		
	}
	
	/**
	 * 员工的删除
	 */
	public int deleteWorker(Worker worker) {
		String sql = "delete from worker where worker_id=?";
		int ob = worker.getWorker_id();
		return super.update(sql, ob);
		
	}
	
	/**
	 * 员工的查询(查询所有)
	 */
	public List<Worker> selectAllWorker() {
		String sql = "select * from worker";
		return super.query2(sql, Worker.class);
		
	}
	
	/**
	 * 员工的查询(通过id)
	 */
	public List<Worker> selectByWorker_id(Worker worker) {
		String sql = "select * from worker where worker_id = ?";
		int ob = worker.getWorker_id();
		return super.query2(sql, Worker.class, ob);
		
	}
	
	/**
	 * 员工的查询(通过姓名)
	 */
	public List<Worker> selectByWorker_name(Worker worker) {
		String sql = "select * from worker where worker_name = ?";
		String ob = worker.getWorker_name();
		return super.query2(sql, Worker.class, ob);
		
	}
	
	/**
	 * 员工的查询(通过账号)
	 */
	public List<Worker> selectByWorker_username(Worker worker) {
		String sql = "select * from worker where worker_username = ? and worker_password = ?";
		Object[] ob = {worker.getWorker_username(),worker.getWorker_password()};
		return super.query2(sql, Worker.class, ob);
		
	}
	
	/**
	 * 员工的查询(通过工作状态=空闲)
	 */
	public List<Worker> selectByWorker_state0() {
		String sql = "select * from worker whrere worker_state = 0";
		
		return super.query2(sql, Worker.class);
		
	}
	
	/**
	 * 员工的查询(通过工作状态=忙碌)
	 */
	public List<Worker> selectByWorker_state1() {
		String sql = "select * from worker whrere worker_state = 1";
		
		return super.query2(sql, Worker.class);
		
	}
}
